#include <iostream>
#include <sstream>
#include <cstring>
#include <algorithm>

using namespace std;

char line[100];

typedef struct _TDate {
	int week, day, month, year;
} TDate;

TDate date;
string weekName[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
	"Friday", "Saturday"};
string monthName[] = {"January", "February", "March", "April", "May", "June",
	"July", "August", "September", "October", "November", "December"};
int monthDay[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

char oldBaseDateStr[] = "Thursday 4 October 1582";
TDate oldBaseDate;
char newBaseDateStr[] = "Friday 15 October 1582";
TDate newBaseDate;

int totalDayByYOld[3000];
int totalDayByYNew[3000];

int oriWeekNew, oriWeekOld;

void showDate(TDate result, bool isNewRule=false) {
	cout << weekName[result.week] << " "
		<< result.day << (isNewRule?"* ":" ")
		<< monthName[result.month] << " "
		<< result.year << endl;
}

TDate parse(char* inStr) {
	TDate date;
	stringstream ss(stringstream::in | stringstream::out);
	ss << inStr;
	string week;
	ss >> week;
	for (int i=0; i<7; ++i)
		if (week == weekName[i]) {
			date.week = i;
			break;
		}
	int day;
	ss >> day;
	date.day = day;
	string month;
	ss >> month;
	for (int i=0; i<12; ++i) 
		if (month == monthName[i]) {
			date.month = i;
			break;
		}
	int year;
	ss >> year;
	date.year = year;
	return date;
}

int toOrigin(TDate x, bool isNew) {
	int num = 0;
	for (int i=0; i<x.month; ++i)
		num += monthDay[i];
	num += x.day-1;
	if (x.month > 1) {
		if (x.year % 4 == 0) {
			if (x.year % 100 == 0) {
				if (isNew) {
					if (x.year % 400 != 0)
						--num;
				}
			}
			++num;
		}
	}
	num += 365*(x.year-1);
	num += (x.year-1) / 4;
	if (isNew)
		num += -(x.year - 1) / 100 + (x.year - 1) / 400;
// 	if (isNew)
// 		num += 2;
	return num;
}

TDate toCalendar(int x, bool isNew) {
	x = x+1;
	TDate res;

	bool leap = false;

	if (isNew) {
		res.week = (x+oriWeekNew-1)%7;
		res.year = lower_bound(totalDayByYNew, totalDayByYNew+3000, x) - totalDayByYNew-1;
		x = x - totalDayByYNew[res.year];
		if (res.year % 4 == 0) {
			leap = true;
			if (res.year % 100 == 0) {
				if (res.year % 400 != 0)
					leap = false;
			}
		}
		if (leap)
			monthDay[1] += 1;

		for (int i=0; i<12; ++i)
			if (x - monthDay[i] <= 0) {
				res.month = i;
				break;
			}
			else
				x -= monthDay[i];

		res.day = x;

		if (leap)
			monthDay[1] -= 1;

	}else{
		res.week = (x+oriWeekOld-1)%7;
		res.year = lower_bound(totalDayByYOld, totalDayByYOld+3000, x) - totalDayByYOld-1;
		x = x - totalDayByYOld[res.year];
		if (res.year % 4 == 0)
			leap = true;
		if (leap)
			monthDay[1] += 1;

		for (int i=0; i<12; ++i)
			if (x - monthDay[i] <= 0) {
				res.month = i;
				break;
			}
			else
				x -= monthDay[i];

		res.day = x;

		if (leap)
			monthDay[1] -= 1;
	}

	return res;
}

int main(void)
{
	oldBaseDate = parse(oldBaseDateStr);
	newBaseDate = parse(newBaseDateStr);

	int oriD = toOrigin(oldBaseDate, false);
	oriWeekOld = ((4-oriD)%7+7)%7;
	oriD = toOrigin(newBaseDate, true);
	oriWeekNew = ((5-oriD)%7+7)%7;

	TDate tmp;
	tmp.day = 1;
	tmp.month = 0;

	for (int i=2; i<3000; ++i) {
		tmp.year = i;
		totalDayByYOld[i] = toOrigin(tmp, false);
		totalDayByYNew[i] = toOrigin(tmp, true);
	}




// 	cout << toOrigin(oldBaseDate, false) << " " << toOrigin(newBaseDate, true) << endl;
// 	TDate debug;
// 	debug.year = 1;
// 	debug.month = 0;
// 	debug.day = 8;
// 	debug.week = oriWeekOld;
// 	showDate(debug);
// 	cout << toOrigin(debug, false) << endl;
// 	showDate(toCalendar(toOrigin(debug, false), false));
// 	cout << endl;
// 	showDate(oldBaseDate);
// 	showDate(toCalendar(toOrigin(oldBaseDate, false),false));
// 	showDate(toCalendar(toOrigin(oldBaseDate, false)+1,false));
// 	showDate(newBaseDate);
// 	showDate(toCalendar(toOrigin(newBaseDate, true), true));
// 	showDate(toCalendar(toOrigin(newBaseDate, true)+1, true));
// 	showDate(toCalendar(toOrigin(oldBaseDate, false)+1, true));
// 
// 	char xxx[] = "Saturday 16 August 1992";
// 	debug = parse(xxx);
// 	cout << oriWeekOld << " " << oriWeekNew << endl;
// 	cout << (toOrigin(debug, false)+oriWeekOld)%7 << " " 
// 		<< (toOrigin(debug, true)+oriWeekNew)%7 << endl;
// 	showDate(toCalendar(toOrigin(debug, false), true));
//  	return 0;





	while (true) {
		memset(line, 0, 100);
		cin.getline(line, 100);
		if (line[0] == '#') break;
		date = parse(line);
// 		showDate(date);
		
		int toOriD;
		toOriD = toOrigin(date, true);
		bool isNewRule = ((toOriD+oriWeekNew)%7 == date.week);

		if (isNewRule) toOriD += 2;

// 		cout << "is new: " << isNewRule << endl;

		TDate result;
		if (isNewRule)
			result = toCalendar(toOriD, false);
		else {
			toOriD = toOrigin(date, false)-2;
// 			cout << "is old: " << ((toOriD+oriWeekOld)%7==date.week) << endl;
			result = toCalendar(toOriD, true);
		}

		showDate(result, isNewRule);

// 		cout << endl;
	}
	return 0;
}
